<template>
  <div>
    <div class="box">
      <div class="box-body mgt20">
        <el-form :model="query" label-position="top">
          <el-row :gutter="15">
            <el-col :span="4">
              <el-form-item label="姓名:">
                <el-input v-model="query.name" />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="联系电话:">
                <el-input v-model="query.phone" />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="邮箱:">
                <el-input v-model="query.email" />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="状态:">
                <el-select v-model="query.status" multiple placeholder="选择状态">
                  <el-option v-for="(value, key) in MemberStatus" :key="key" :label="value" :value="key"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="" class="no-top-label">
                <el-button type="primary" icon="search" @click="loadPage(1)">检索</el-button>
                <!-- <el-button @click="">导出对账单</el-button> -->
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
  
    <el-table :data="page.content" v-loading.body="loading" border>
      <el-table-column prop="name" label="姓名"/>
      <el-table-column prop="phone" label="联系电话" />
      <el-table-column prop="email" label="邮箱" />
      <el-table-column prop="password" label="密码" />
      <el-table-column prop="status" label="状态" >
        <template slot-scope="scope">
          {{MemberStatus[scope.row.status.toString()]}}
        </template>
      </el-table-column>
      <el-table-column label="操作" >
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === 0" @click="enable(scope.row.id)" size="small" type="success">启用</el-button>
          <el-button v-if="scope.row.status === 1" @click="disable(scope.row.id)" size="small" type="warning">禁用</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- pagination -->
    <el-pagination @current-change="showPage" :current-page.sync="page.page" :page-size="page.pageSize" 
      :total="page.totalElements" layout="total, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
import { Balance, Member } from '@/store/api'
import * as Constants from '@/constants'
import Pagination from '@/utils/pagination'

export default {
  name: 'dtb-account',
  props: {
    dtbId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      ...Constants,
      loading: true,
      query: {
        dtbId: this.dtbId,
        status: ['0', '1']
      },
      page: {
        content: []
      }
    }
  },
  created () {
    this.loadPage(1)
  },
  methods: {
    ...Pagination,
    list(page, query) {
      this.loading = true
      return Balance.accounts(query).then((data) => {
        this.page = data
        this.loading = false
      })
    },
    enable(memberId) {
      Member.enable(memberId).then(() => {
        this.reloadPage()
      })
    },
    disable(memberId) {
      Member.disable(memberId).then(() => {
        this.reloadPage()
      })
    }
  }
}
</script>
